//
//  WBVisitorView.m
//  TransWB
//
//  Created by 孝飞王 on 2016/12/28.
//  Copyright © 2016年 孝飞王. All rights reserved.
//

#import "WBVisitorView.h"
#import "SDAutoLayout.h"
@implementation WBVisitorView

- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self == [super initWithFrame:frame]) {
        
        [self setUpUI];
    }
    return self;
}

- (void)setUpUI{
    
    self.backgroundColor = [UIColor cz_colorWithHex:0xEDEDED];
    
    //添加子视图
    [self addSubview:self.bacagroundImage];
    [self addSubview:self.homeImageView];
    [self addSubview:self.registBtn];
    [self addSubview:self.longinbtn];
    [self addSubview:self.labelView];
    [self insertSubview:self.maskImageView belowSubview:self.homeImageView];
   
}
- (void)startAnimation{
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    animation.fromValue = 0;
    animation.toValue = @(M_PI * 2);
    animation.repeatCount = MAXFLOAT;
    animation.duration = 8;
    animation.removedOnCompletion = NO;
    [self.bacagroundImage.layer addAnimation:animation forKey:nil];
    
}

#pragma mark - 设置布局
- (void)layoutSubviews{
    
    self.bacagroundImage.sd_layout
    .centerXEqualToView(self)
    .centerYIs(self.center.y - 60);
    
    self.homeImageView.sd_layout
                                        .centerXEqualToView(self.bacagroundImage)
                                        .centerYEqualToView(self.bacagroundImage);
    
    
    self.maskImageView.sd_layout
                                      .centerXEqualToView(self.homeImageView)
                                      .centerYIs(self.center.y-160)
                                      .widthIs(Screen_Width)
                                      .heightIs(Screen_Height+200);
    
    self.labelView.sd_layout.centerXEqualToView(self.bacagroundImage).topSpaceToView(self.homeImageView,20).widthRatioToView(self,0.7).autoHeightRatio(0);

    
        self.registBtn.sd_layout
                              .topSpaceToView(self.labelView,30)
                              .widthIs(100)
                              .centerXIs(self.center.x - 60)
                              .heightIs(40);
    
     self.longinbtn.sd_layout
                            .topSpaceToView(self.labelView,30)
                            .widthIs(100)
                            .centerXIs(self.center.x + 60)
                            .heightIs(40);

    [super layoutSubviews];
}


#pragma mark - 小房子
- (UIImageView *)homeImageView{
    
    if (_homeImageView == nil) {
        _homeImageView = [[UIImageView alloc]initWithImage://SDAutoLaout  在没有图片的情况下是不行的
                                   [UIImage imageNamed:@"visitordiscover_feed_image_house"]];
    }
    return _homeImageView;
}

#pragma mark - 背景图
- (UIImageView *)bacagroundImage{
    
    if (_bacagroundImage == nil) {
        _bacagroundImage = [[UIImageView alloc]initWithImage:
                                    [UIImage imageNamed:@"visitordiscover_feed_image_smallicon"]];
    }
    return _bacagroundImage;
}

#pragma mark - 注册按钮
- (UIButton*)registBtn{
    
    if (_registBtn == nil) {
        _registBtn = [UIButton cz_textButton:@"注册" fontSize:16 normalColor:[UIColor orangeColor ] highlightedColor:[UIColor darkGrayColor] backgroundImageName:@"common_button_white_disable"];
    }
    return _registBtn;
}

#pragma mark - 登录按钮
- (UIButton *)longinbtn{
    
    if (_longinbtn == nil) {
        _longinbtn = [UIButton cz_textButton:@"登录" fontSize:16 normalColor:
                            [UIColor darkGrayColor ]
                            highlightedColor:[UIColor orangeColor]
                            backgroundImageName:@"common_button_white_disable"];
    }
    return _longinbtn;
}

#pragma mark - 信息按钮
- (UILabel *)labelView{
    
    if (_labelView == nil) {
        _labelView = [UILabel cz_labelWithText:
                      @"关注一些人,\n回这里看看有什么惊喜"
                      fontSize:14 color:[UIColor darkGrayColor]];
        //_labelView.backgroundColor = [UIColor cyanColor];
          }
    return _labelView;
}

#pragma mark - 遮挡视图
- (UIImageView *)maskImageView{
    
    if (_maskImageView == nil) {
        _maskImageView = [[UIImageView alloc]initWithImage:
                          [UIImage imageNamed:@"visitordiscover_feed_mask_smallicon"]];
    }
    return _maskImageView;
}

- (void)setDataDic:(NSDictionary *)dataDic{
    
    _dataDic = dataDic;
    
    if ([dataDic[@"imageName"] isEqualToString:@""]) {
        [self startAnimation];
        return;
    }
    
    self.labelView.text = dataDic[@"title"];
    self.bacagroundImage.image = [UIImage imageNamed:dataDic[@"imageName"]];
    self.homeImageView.hidden = YES;
    self.maskImageView.hidden = YES;
}









@end
